package net.sppan.base.dao;

import java.util.Date;

import net.sppan.base.dao.support.IBaseDao;
import net.sppan.base.entity.CommentExuser;
import net.sppan.base.entity.CommentExuserView;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

@Repository
@Transactional(isolation = Isolation.READ_COMMITTED)
public interface ICommentExuserDao extends IBaseDao<CommentExuser, Long>{

	/**
	 *          Long id, Long commentId, Long dyContentId,
				String commentDyId, Date uploadDate, String commentContent,
				Long praiseNum, Long replyNum, String replyToDyId,
				String replyToCommentId, Long commentType, String mediaIds,
				Integer type, String mediaJson, Date inputTime, Long exuserId,
				String operationCode, Date allotTime, Date exTime,
				String exResult, String exDesc, String sysStatus,
				String nickName, String headPortraitUrl
	 * @param userId
	 * @param pageable
	 * @return
	 */
	@Query(value="select new net.sppan.base.entity.CommentExuserView( "
			+ "  e.id,e.commentId,e.dyContentId,e.commentDyId,e.uploadDate ,e.commentContent, "
			+ "  e.praiseNum,e.replyNum,e.replyToDyId,e.replyToCommentId ,e.commentType ,e.mediaIds, "
			+ "  e.type,e.mediaJson,e.inputTime,e.exuserId,e.operationCode,e.allotTime,e.exTime, "
			+ "   e.exResult,e.exDesc,e.sysStatus ,u.nickName,u.headPortraitUrl ) "
			+ " from  CommentExuser e , DyUserInfo u "
			+ " where  e.commentDyId=u.dyId "
			+ " and e.exuserId=:userId and e.exResult=0 "
			+ " ORDER  BY e.id DESC  "
			,countQuery =" select count(*)  from  CommentExuser e ,DyUserInfo u where  e.commentDyId=u.dyId and e.exuserId=:userId  and e.exResult=0  ")
	public Page<CommentExuserView> findCommentExuserPage(@Param("userId") Long userId, Pageable pageable);
 
	
	
	@Modifying
	@Query(value ="update CommentExuser set exResult=:exResult , allotTime=:allotTime , exuserId=:userId where id =:id")
	public void updateCommentExuserDao(@Param("exResult")String exResult,@Param("userId")Long userId,@Param("allotTime")Date allotTime,@Param("id")Long id);

	
}
